import mockAS2.IMockAS2;
import mockAS2.Sandbox;
import mockAS2.SpyMethod;
import mockAS2.SpyObject;
import mockAS2.Stub;

/**
 * Copyright (c) 2012 Gary Higham
 * Released under the MIT license
 * https://code.google.com/p/mock-as2/wiki/License
 *
 * Version: v0.1
 */
class mockAS2.MockAS2 {
	
	private static var sandbox : Sandbox;
	
	public static function createSandbox() : Sandbox {
		sandbox = new Sandbox();
		return sandbox;
	}

	public static function getSandbox() : Sandbox {
		return sandbox;
	}
	
	public static function restoreSandbox() : Void {
		sandbox.restore();
	}

	public static function createStub(object : Object, method : String, stubMethod : Function) : Stub {
		return Stub(addItemToSandbox(new Stub(object, method, stubMethod)));
	}

	public static function createSpyOnObject(parentObject : Object, objectToWatch : String) : SpyObject {
		return SpyObject(addItemToSandbox(new SpyObject(parentObject, objectToWatch)));
	}

	public static function createSpyOnMethod(object : Object, method : String) : SpyMethod {
		return SpyMethod(addItemToSandbox(new SpyMethod(object, method)));
	}
	
	private static function addItemToSandbox(item : IMockAS2) : IMockAS2 {
		sandbox.addItem(item);
		return item; 
	}
}
